﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace WcfService
{
    public class FaultService : IFaultService
    {
        public void ThrowFault1()
        {
            PrintToken();
            throw new FaultException("直接抛出FaultException");
        }

        public void ThrowFault2()
        {
            PrintToken();
            throw new FaultException("单向通信方法，客户端没有错误消息");
        }

        public void ThrowFault3()
        {
            PrintToken();
            throw new FaultException<string>("抛出基元类型string的FaultException<T>");
        }

        public void ThrowFault4()
        {
            PrintToken();
            throw new FaultException<FaultInfo>(new FaultInfo("FaultService.GetData", "抛出自定义错误信息的FaultException<T>"));
        }

        private void PrintToken()
        {
            string token = OperationContext.Current.IncomingMessageHeaders.GetHeader<string>("AccessToken", "ywt.WcfTest");
            Debug.Print(token);
        }
    }
}
